import coin.exchange.base.kr_rest.native_public_client_base as npubcb
import coin.exchange.bitfinex_v2.kr_rest.constants as exchange_constants


class BitfinexNativePublicClient(npubcb.NativePublicClientBase):
  precision_list = ["P0", "P1", "P2", "P3", "R0"]

  def __init__(self):
    npubcb.NativePublicClientBase.__init__(self, url="https://api.bitfinex.com/v2")

  def get_status(self):
    return self._get_as_json("platform/status")

  def get_tickers(self, symbols):
    return self._get_as_json("tickers", params=dict(symbols=symbols))

  def get_ticker(self, symbol):
    return self._get_as_json("ticker/%s" % (symbol))

  def get_trades(self, symbol):
    return self._get_as_json("trades/%s/hist" % (symbol))

  def get_books(self, symbol, precision):
    assert precision in self.precision_list
    return self._get_as_json("book/%s/%s" % (symbol, precision))

  def get_recent_transactions(self, symbol):
    return self._get_as_json("recent_transactions/%s" % (symbol))

  def queryAll(self):
    print(self.get_status())
    for symbol in exchange_constants.native_symbol_list_for_test:
      print(self.get_ticker(symbol))
      print(self.get_trades(symbol))
      for precision in self.precision_list:
        print(self.get_books(symbol, precision))
